//
// Particle.cs
//
// Copyright (C) 2006 Alp Toker <alp@atoker.com>
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
//

using System;
using System.Collections.Generic;

namespace Dashboard.Mint.Physics {

	public class Particle {

		public double Mass;
		public double Theta;

		public Vector Force;

		public Point Position;
		public Point PreviousPosition;
		public Vector Velocity;

		public double GetDistance (Point p)
		{
			Vector d = Position - p;
			return Math.Sqrt ((d.X * d.X) + (d.Y * d.Y));
		}

		public void AccumulateForces (Model Model)
		{
			// Gravity
			Force = Model.Gravity * Mass;

			// Friction
			Vector v = Position - PreviousPosition;

			Force -= v * Model.Friction;
		}

		public void Integrate (double step)
		{
			Point original_position = Position;
			Position += Position - PreviousPosition + Force * (step * step);
			PreviousPosition = original_position;
		}
	}
}
